import router from '@system.router';
import http from '@ohos.net.http';

export default {
    data: {
        searchInfo: "",
        title: "demo",
        images: [{"itemId":3,imgPath:"http://106.12.150.68:8080/image/item/3/IMG_3_4.jpg"},
        {"itemId":2,imgPath:"http://106.12.150.68:8080/image/item/2/IMG_2_4.jpg"},
        {"itemId":4,imgPath:"http://106.12.150.68:8080/image/item/4/IMG_4_4.jpg"},
        {"itemId":5,imgPath:"http://106.12.150.68:8080/image/item/5/IMG_5_2.jpg"},
        ],
        navg: [{
                   "title": "一七上新", imgSrc: "/common/images/ring.png"
               },
               {
                   "title": "手机", imgSrc: "/common/images/smartphone.png"
               },
               {
                   "title": "12S系列", imgSrc: "/common/images/12.png"
               },
               {
                   "title": "电视", imgSrc: "/common/images/TV.png"
               },
               {
                   "title": "冰空洗", imgSrc: "/common/images/aircondition.png"
               },
               {
                   "title": "新人福利", imgSrc: "/common/images/boon.png"
               },
               {
                   "title": "一七众筹", imgSrc: "/common/images/drink.png"
               },
               {
                   "title": "平板/电脑", imgSrc: "/common/images/pad.png"
               },
               {
                   "title": "生活电器", imgSrc: "/common/images/fan.png"
               },
               {
                   "title": "智能家居", imgSrc: "/common/images/smarthome.png"
               },],
        commodity: [],
    },
    onInit() {
        // 每一个httpRequest对应一个http请求任务，不可复用
        let httpRequest = http.createHttp();

        httpRequest.request(
        // 填写http请求的url地址，可以带参数也可以不带参数。URL地址需要开发者自定义。GET请求的参数可以在extraData中指定
        this.$app.$def.getItemSearchUrl(),
            {
                method: 'GET',
            }, (err, data) => {
            if (!err) {
                // data.result为http响应内容，可根据业务需要进行解析
                console.info('Result:' + data.result);
                console.log("--------->")
                this.$app.$def.globalData.jsonResult = JSON.parse(data.result);
                this.commodity = this.$app.$def.globalData.jsonResult.info;
                console.info('code:' + this.$app.$def.globalData.jsonResult);
                console.info('msg:' + this.$app.$def.globalData.jsonResult);
            } else {
                console.info('error:' + err.data);
            }
        }
        );
    },
    search() {
        console.log("触发了搜索")
        console.log(this.searchInfo)
            router.push({
            uri: "pages/searchlist/searchlist",
            params:{searchInfo:this.searchInfo}
        })
    },
    searchinfo(event) {
        this.searchInfo = event.value;
        console.log(this.searchInfo);
    },
    onjump(index) {
        router.push({
            uri: "pages/detail/detail",
            params: {
                commodity: this.commodity[index]
            }
        })
    },
    test(sinfo){
        router.push({
            uri: "pages/searchlist/searchlist",
            params:{searchInfo:sinfo}
        })
    }

}
